package com.resifind.www.exception;

import com.resifind.www.constant.ErrorCode;

/**
 * @author 36069
 */
public class Resp<T> {
    private int code;
    private String msg;
    private T data;

    public Resp(int code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static <T> Resp<T> success(String msg, T data) {
        return new Resp<>(200, msg, data);
    }

    public static <T> Resp<T> success(T data) {
        return new Resp<>(200, "success", data);
    }

    public static <T> Resp<T> error(ErrorCode errorCode) {
        return new Resp<>(errorCode.getCode(), errorCode.getMsg(), null);
    }

    public static <T> Resp<T> error(int code, String msg) {
        return new Resp<>(code, msg, null);
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public void setData(T data) {
        this.data = data;
    }

    public T getData() {
        return data;
    }
}
